package com.hhsjdesign.dynamicui.businessdata

class BaseModel<T> {

    var code: Int = 0

    var message: String = ""

    //0 object, 1 array
    var type: Int = 0

    var result: T? = null

    var page: Page? = null

    var resultList: MutableList<T>? = null

    open class Page {
        //如 199条

        //如201条

        //页码
        var pageNo: Int = 1

        //每页数量
        var pageLimit: Int = 20

        //总页数
        var pageNumber: Int = 10

        //当前页数
        var currentPageNumber: Int = 10
    }

    /**
     * 接口数据转成 视图可用数据
     */
     fun  toIViewableList(): MutableList<IViewable<T>> {
        val viewableList: MutableList<IViewable<T>> = ArrayList()
        for (t in resultList!!) {
            if (t is IViewable.IViewableTransformer) {
                t.toViewable()?.also {
                    viewableList.add(it as IViewable<T>)
                }
            }
        }
        return viewableList
    }

    companion object {
        //数组
        const val ARRAY: Int = 1;

        //字典
        const val OBJECT: Int = 0;

        //成功
        const val SUCCESS: Int = 0;

        //失败
        const val FAIL: Int = -1;
    }
}